package com.cjg.scrolldemo;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cjg.scrolldemo.databinding.FragmentTabBinding;

import java.util.ArrayList;
import java.util.List;

public class CPersonFragment extends Fragment {
    private CPersonTab1Adapter adapter;
    private FragmentTabBinding binding;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding=FragmentTabBinding.inflate(inflater, container, false);//使用DataBind 1
        binding.setLifecycleOwner(this);//使用DataBind 2
//        View view = inflater.inflate(R.layout.fragment_tab, container, false);
//        recyclerView = view.findViewById(R.id.recyclerview);

        adapter = new CPersonTab1Adapter(getArrayList());//创建适配器
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.HORIZONTAL,false));//设置LayoutManager，以LinearLayoutManager为例子进行线性布局
        binding.recyclerview.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.HORIZONTAL));//设置分割线
        binding.recyclerview.setNestedScrollingEnabled(false);
        binding.recyclerview.setAdapter(adapter);//设置适配器

        return binding.getRoot();//view; //使用DataBind 3
    }

    //模拟数据
    private List<String> getArrayList() {
        List<String> dataList = new ArrayList<>();
        for (int n = 0; n < 10; n++) {
            dataList.add(" " + n);
        }
        return dataList;
    }
}
